package com.hbnu.controller;

import com.hbnu.pojo.Request;
import com.hbnu.pojo.Result;
import com.hbnu.service.AdmerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@CrossOrigin(origins = "*")
@RestController
public class AdmerController {

    @Autowired
    private AdmerService admerService;

    @PostMapping("/admerLogin")
    public Result login(@RequestBody Request rq){
        if(rq.getAid().equals("hbnu123456")&&rq.getPassword().equals("123456"))
            return Result.success(2);

        if(admerService.login(rq)==1)return Result.success(1);
        else return Result.error("账号密码错误");
    }

    @PostMapping("/admerRegister")
    public Result register(@RequestBody Request rq){
        try{
            admerService.register(rq);
            return Result.success();
        }catch (Exception e){
            return Result.error("账号重复");
        }
    }
}
